﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class admin_addJF : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["IsAuthorized"] = true;
        if (Request.QueryString["jfid"] != null && !Page.IsPostBack)
        {
            DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
            if (dv.Table.Rows.Count != 0)
            {//jfID, j_Name, j_address, j_class, j_jsh, j_zy, j_kfsj_s, j_kfsj_e
                tbxJSM.Text = dv[0]["j_Name"].ToString();//
                tbxJSDZ.Text = dv[0]["j_address"].ToString();
                ddlJSLX.Text = dv[0]["j_class"].ToString();
                tbxJSH.Text = dv[0]["j_jsh"].ToString();
                tbxJSZY.Text = dv[0]["j_zy"].ToString();
                tbxKFSJ.Text = dv[0]["j_kfsj_s"].ToString();
                tbxGBSJ.Text = dv[0]["j_kfsj_e"].ToString();
            }
            else
            {
                // 没有找到这个ID的文章
            }
        }
    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["jfid"] == null)
        {
            SqlDataSource1.Insert();
            Response.Redirect("EditJF.aspx");
        }
        else
        {
            SqlDataSource1.Update();
            Response.Redirect("EditJF.aspx");
        }
    }
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters[0].Value = Request.QueryString["jfID"];
    }
    protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        //(j_Name=@Param1, j_address=@Param2, j_class=@Param3, j_jsh=@Param4, j_zy=@Param5, j_kfsj_s=@Param6, j_kfsj_e=@Param7 ) WHERE JFID=@Param8
        e.Command.Parameters[0].Value = tbxJSM.Text;
        e.Command.Parameters[1].Value = tbxJSDZ.Text;
        e.Command.Parameters[2].Value = ddlJSLX.Text;
        e.Command.Parameters[3].Value = tbxJSH.Text;
        e.Command.Parameters[4].Value = tbxJSZY.Text;
        e.Command.Parameters[5].Value = tbxKFSJ.Text;
        e.Command.Parameters[6].Value = tbxGBSJ.Text;
        e.Command.Parameters[7].Value=Request.QueryString["jfid"].ToString();
    }
    protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        //j_Name, j_address, j_class, j_jsh, j_zy, j_kfsj_s, j_kfsj_e
        e.Command.Parameters[0].Value = tbxJSM.Text;
        e.Command.Parameters[1].Value = tbxJSDZ.Text;
        e.Command.Parameters[2].Value = ddlJSLX.Text;
        e.Command.Parameters[3].Value = tbxJSH.Text;
        e.Command.Parameters[4].Value = tbxJSZY.Text;
        e.Command.Parameters[5].Value = tbxKFSJ.Text;
        e.Command.Parameters[6].Value = tbxGBSJ.Text;
    }
}